﻿using System.Threading;
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;

namespace Syngine.Physics
{
	/// <summary>
	/// 
	/// </summary>
	public static class WorldContext
	{
		private static World _world;

		static WorldContext()
		{
		}

		/// <summary>
		/// 
		/// </summary>
		public static World World
		{
			get
			{
				return _world;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="world"></param>
		public static void Set(World world)
		{
			Interlocked.Exchange(ref _world, world);
		}

		public static void SetGravity(float gravity)
		{
			SetGravity(new Vector2(0, gravity));
		}

		public static void SetGravity(Vector2 gravity)
		{
			_world.Gravity = gravity;
		}

		/// <summary>
		/// Steps the world the specified time.
		/// </summary>
		/// <param name="time">The time.</param>
		public static void Step(float time)
		{
			if (!GameState.IsPaused)
			{
				_world.Step(time);
			}
		}
	}
}